package me.jiatao.usercenter.mvp.presenter

import me.jiatao.baselibrary.mvp.presenter.BasePresenter
import me.jiatao.baselibrary.rx.BaseSubscriber
import me.jiatao.baselibrary.rx.execute
import me.jiatao.usercenter.data.protocol.UserInfo
import me.jiatao.usercenter.mvp.view.LoginView
import me.jiatao.usercenter.mvp.service.impl.UserServiceImpl
import javax.inject.Inject

class LoginPresenter @Inject constructor() : BasePresenter<LoginView>() {

    @Inject
    lateinit var userService: UserServiceImpl

    fun login(mobile: String, pwd: String) {

        if (!checkNetWork()) {
            return
        }

        mView.showLoading()

        userService
            .login(mobile, pwd)
            .execute(object : BaseSubscriber<UserInfo>(mView) {
                override fun onNext(data: UserInfo) {
                    mView.onLoginResult(data)
                    mView.hideLoading()
                }
            }, mLifecycleProvider)
    }
}